package UIUtils
{
	public class uif_color extends Object {
		public function uif_color() {
			super();
		}
		
		public static function uintToRGBA(color: uint): Array {
			return [((color & 0xFF000000) >> 24) & 0xFF, (color & 0xFF0000) >> 16, (color & 0xFF00) >> 8, color & 0xFF];
		}
		
		public static function rgbaToUint(color: Array): uint {
			return (color[0] << 24) | (color[1] << 16) | (color[2] << 8) | color[3];
		}
		
		public static function RGB(r: uint, g: uint, b: uint): uint {
			return (r << 16) | (g << 8) | b;
		}
		
		public static function computeRGBA(a_from: uint, a_to: uint, a_delta: Number): uint {
			var a1: Array = uintToRGBA(a_from);
			var a2: Array = uintToRGBA(a_to);
			var result: Array = new Array();
			for (var i: int=0; i<4; i++)
				result[i] = Math.round(a1[i] + (a2[i] - a1[i]) * a_delta);
			return rgbaToUint(result);
		}
		
		public static function sineColor(a_state: Number, RMull: Number, GMull: Number, BMull: Number,
									RMax: uint = 0xFF, GMax: uint = 0xFF, BMax: uint = 0xFF): uint {
			return uif_color.RGB(
				Math.round((Math.sin(a_state * RMull) + 1) * RMax * 0.5),
				Math.round((Math.sin(a_state * GMull) + 1) * GMax * 0.5),
				Math.round((Math.sin(a_state * BMull) + 1) * BMax * 0.5)
			);
		}
		
		public static function rnd(RMax: uint = 0xFF, GMax: uint = 0xFF, BMax: uint = 0xFF): uint {
			return uif_color.RGB(
				Math.random() * RMax,
				Math.random() * GMax,
				Math.random() * BMax
			);
		}		
	}
}